package com.hc.pokemen.feature_pokemen.data.repository


import com.hc.pokemen.feature_pokemen.data.mapper.toPokemon
import com.hc.pokemen.feature_pokemen.data.mapper.toPokemonList
import com.hc.pokemen.feature_pokemen.data.remote.PokemonApi
import com.hc.pokemen.feature_pokemen.domain.entity.Pokemon
import com.hc.pokemen.feature_pokemen.domain.entity.PokemonList
import com.hc.pokemen.feature_pokemen.domain.repository.PokemonRepository
import com.hc.pokemen.feature_pokemen.domain.util.Resource


class PokemonRepositoryImpl(private val api: PokemonApi) : PokemonRepository {
    override suspend fun getPokemon(name: String): Resource<Pokemon> {
        try {
            val data = api.getPokemonInfo(name = name)
            return Resource.Success(data.toPokemon())
        }catch (e:Exception){
            return Resource.Error("请求错误")
        }
    }

    override suspend fun getPokemonList(limit: Int, offset: Int): Resource<PokemonList> {
        try {
            val data = api.getPokemonList(limit, offset)
            return Resource.Success(data.toPokemonList())
        } catch (e: Exception) {
            return Resource.Error("请求错误")
        }
    }

}